Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trigger post hook on Event Copy #12990

Merged
merged 1 commit into from
Nov 13, 2018

Conversation

mattwire
Copy link
Contributor

Overview

When creating a copy of an event via API Event.create (with a template ID) (or directly using the CRM_Event_BAO_Event::copy function - as called from ManageEvents-"Copy" in the UI) a "copy" hook is called but the expected Event.create hook is not called, despite a new event being created.

In addition the copy function (which is only called in two places) has complexities to support passing in an already copied event. This seems unnecessarily complex and this PR simplifies that so it is always responsible for creating the copied event.

Note: Copying events via the "Repeat Events" (RecurringEntity) functionality doesn't use this function... It hardcodes it's own version which should be replaced with this copy function in a future PR.

Before

CRM_Event_BAO_Event::copy() doesn't call the "create" hook when an event is created and adds unnecessary complexity by allowing an already created event to be passed in.

After

CRM_Event_BAO_Event::copy() calls the "create" (post) hook when an event is created and simplifies the function so it is easier to maintain and simpler.

Technical Details

The "pre" hook is still not implemented because this would require conversion from an object to a params array and changes can be made via the "post" hook if required.

Comments

This change should be NFC. The API remains the same, if extensions are calling CRM_Event_BAO_Event::copy() directly (which is unsupported) they will need to switch to use the API. However I'm not aware of any extensions that do call that function.

@civibot
Copy link

civibot bot commented Oct 23, 2018

(Standard links)

@civibot civibot bot added the master label Oct 23, 2018
@eileenmcnaughton
Copy link
Contributor

@mattwire there is a style warning.

Could the hooks go in copyGeneric?

@mattwire mattwire changed the title Trigger post hook on Event Copy WIP Trigger post hook on Event Copy Oct 24, 2018
@mattwire mattwire force-pushed the event_copy_posthook branch 2 times, most recently from ce57ce1 to 395b858 Compare October 29, 2018 21:51
@mattwire mattwire force-pushed the event_copy_posthook branch from 395b858 to ae70f47 Compare October 29, 2018 21:53
@mattwire
Copy link
Contributor Author

Could the hooks go in copyGeneric?

Yes. Much better, then it triggers on all the entities that are copied.

@@ -98,6 +98,7 @@ public function preProcess() {
$components = array('Contact', 'Contribute', 'Member', 'Event', 'Pledge', 'Case', 'Grant', 'Activity');

// FIXME: This should use a modified version of CRM_Contact_Form_Search::getModeValue but it doesn't have all the contexts
// FIXME: Or better still, use CRM_Core_DAO_AllCoreTables::getBriefName($daoName) to get the $entityShortName
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, this is comment is unrelated to this PR... but I was looking for a function to get the Entity shortname and I found it!

@mattwire mattwire changed the title WIP Trigger post hook on Event Copy Trigger post hook on Event Copy Oct 29, 2018
Copy link
Contributor

@jitendrapurohit jitendrapurohit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested this and confirmed the call of post hook on Event copy as well as while creating a copy of a Contribution page.

Also tested an API call with $params['template_id'] and it copies the event correctly.

ok to merge.

@@ -920,13 +920,11 @@ public static function &getCompleteInfo(
* @param int $id
* The event id to copy.
* boolean $afterCreate call to copy after the create function
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also remove this line?

@eileenmcnaughton eileenmcnaughton merged commit 86970f6 into civicrm:master Nov 13, 2018
@eileenmcnaughton
Copy link
Contributor

thanks @jitendrapurohit merged. @mattwire - one comment for possible follow up above^^

@eileenmcnaughton
Copy link
Contributor

@mattwire is there any related ticket to close?

@mattwire mattwire deleted the event_copy_posthook branch March 1, 2019 11:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants